package cn.colins.raft.task;

import cn.colins.raft.LogManage;
import cn.colins.raft.enity.RaftNodeInfo;
import cn.colins.raft.enums.NodeStatusEnums;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Description 节点日志可能跟leader相比有缺失，所以开启一个定时任务，定时校验，不可能每次都从头来，所以有一个checkpoint,从checkPoint-lastCommitIndex之间校验
 * @Author czl
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2023/7/18
 */
public class LogIndexCheckTask implements Runnable {
    private static final Logger log = LoggerFactory.getLogger(LogIndexCheckTask.class);


    @Override
    public void run() {
        // 只有follow才需要检测
        if (NodeStatusEnums.FOLLOW.equals(RaftNodeInfo.getInstance().getCurrentNodeStatus())
                && null != RaftNodeInfo.getInstance().getCurrentLeader()) {
            LogManage logManage = RaftNodeInfo.getInstance().getLogManage();
            if(logManage!=null){
                logManage.logIndexCheck();
            }
        }
    }
}
